package cn.yanghan.controller;

import cn.yanghan.dto.sendSmsCodeDto;
import cn.yanghan.service.IverifycodeService;
import cn.yanghan.utils.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.io.IOException;

@RestController
@RequestMapping("/verifycode")
public class verifycodeController {

    @Autowired
    private IverifycodeService verifycodeService;

    //图片验证码
    @GetMapping("/imageCode/{key}")
    public AjaxResult creatImageCode(@PathVariable("key") String key) throws IOException {
        String base64 = verifycodeService.creatImageCode(key);
        return AjaxResult.me().setResultObj(base64);
    }

    //短信验证码
    @PostMapping("/sendSmsCode")
    public AjaxResult sendSmsCode(@RequestBody @Valid sendSmsCodeDto dto){
        verifycodeService.sendSmsCode(dto);
        return AjaxResult.me();
    }
}
